<template>
  <div class="config-wrap">
    <h2>系统名称配置</h2>
    <el-form :rules="rules" :model="ruleForm" ref="ruleForm" label-width="100px">
      <el-form-item label="系统名称" prop="systemName">
        <el-input size="small" v-model="ruleForm.systemName" style="width: 300px" placeholder="请输入系统名称" maxlength="20"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="small" @click="submitForm">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "Index",
    data() {
      return {
        ruleForm: {
          systemName: '',
        },
        rules: {
          systemName: [
            {required: true, message: '请输入系统名称', trigger: 'blur'},
            /*{pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+$/, message: '不允许输入空格等特殊符号'}*/
          ]
        }
      };
    },
    created() {
      this.$http.get("/config").then(res => {
        this.ruleForm.systemName = res.systemName;
      })
    },
    methods: {
      submitForm() {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            this.$http.post('/config', {
              systemName: this.ruleForm.systemName,
              id: 1
            }).then(res => {
              this.$store.commit("setSystemName", this.ruleForm.systemName);
              this.$notify.success("保存成功.");
            })
          }
        });
      }
    }
  }
</script>

<style scoped lang="less">

  .config-wrap {
    box-sizing: border-box;
    height: 100%;
    h2 {
      margin-bottom: 15px;
      margin-left: 22px;
    }
  }

</style>
